package com.zhimeng.personal.utils;

import android.content.Context;

import com.zhimeng.personal.data.DataCenter;

import java.io.File;

/**
 * Created by sunzhimeng on 8/31/17.
 */

public class SDCardUtils {

    static String logCacheDir;

    /**
     * 如果存在SD卡则将缓存写入SD卡,否则写入手机内存
     */
    public static String getLogCacheDir(Context context) {
        String logCacheDir;
        if (context.getExternalCacheDir() != null && ExistSDCard()) {
            logCacheDir = context.getExternalCacheDir().toString();
        } else {
            logCacheDir = context.getCacheDir().toString();
        }
        return logCacheDir;
    }

    public static String getCurrentUserDir(Context context) {
        return  getLogCacheDir(context) + File.separator+ DataCenter.getCurrentUser().getPhone()+ File.separator;
    }


    private static boolean ExistSDCard() {
        return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    }
}
